﻿'Imports 

'Important : ToolStripControlHost est un composant qui contient un control, pas un control.
'Il n'a pas de constructor et passer en mode design affiche une erreur.
'C'est une erreur normal !!!

Public Class ToolStripTrackBar2
    Inherits ToolStripControlHost

    Public Sub New()

        MyBase.New(New colorSlider())
        TrackBarControl.Size = New Size(60, 14)
        Me.BackColor = Color.Transparent
        TrackBarControl.Maximum = 200
    End Sub
    Public ReadOnly Property TrackBarControl() As colorSlider
        Get
            Return CType(Control, colorSlider)
        End Get
    End Property

    Public Property Value() As Integer
        Get
            Return TrackBarControl.Value
        End Get
        Set(ByVal value As Integer)
            TrackBarControl.Value = value
        End Set
    End Property

    Protected Overrides Sub OnSubscribeControlEvents(ByVal c As Control)
        MyBase.OnSubscribeControlEvents(c)
        Dim TrackBar As colorSlider = CType(c, colorSlider)
        AddHandler TrackBar.Scroll,
        AddressOf HandleScroll
    End Sub
    Protected Overrides Sub OnUnsubscribeControlEvents(ByVal c As Control)
        MyBase.OnUnsubscribeControlEvents(c)
        Dim TrackBar As colorSlider = CType(c, colorSlider)
        RemoveHandler TrackBar.Scroll,
        AddressOf HandleScroll
    End Sub

    Public Event Scroll As EventHandler

    Private Sub HandleScroll(ByVal sender As Object, ByVal e As EventArgs)
        RaiseEvent Scroll(Me, e)
    End Sub
End Class
